insheet using ../Data/Raw/raw_accuracysurvey_candidates.csv, comma names clear

drop if _n<=5



* participant characteristics

gen gender_male = q9=="Male"
gen gender_female = q9=="Female"
gen gender_nonbinary = q9=="Non-binary"

gen race_white = q1=="White"
gen race_black = q1=="Black or African American"
gen race_other = race_white==0 & race_black==0 // can update later

gen exp_hirese = q60=="Yes"

gen educ_unselective = q17=="Unselective"
gen educ_belavgselective = q17=="Below Average Selectivity"
gen educ_aboavgselective = q17=="Above Average Selectivity"
gen educ_elite = q17=="Highly Selective, Elite"

gen firm_small = q18=="Below 1500 employees"
gen firm_medium = q18=="Between 1500 and 2000 employees"
gen firm_large = q18=="More than 2,000 employees"

* responses about candidates

* elite white woman
rename q11_1 p_acceptinterview_2
rename q10_1 p_passinterview_2
rename q12_1 p_acceptoffer_2
rename q61 interview_2

* non-elite white woman
rename q77_1 p_acceptinterview_3
rename q76_1 p_passinterview_3
rename q78_1 p_acceptoffer_3
rename q79 interview_3

* elite black woman
rename q71_1 p_acceptinterview_4
rename q70_1 p_passinterview_4
rename q72_1 p_acceptoffer_4
rename q73 interview_4

* non-elite black woman
rename q83_1 p_acceptinterview_5
rename q82_1 p_passinterview_5
rename q84_1 p_acceptoffer_5
rename q85 interview_5

* elite white man
rename q65_1 p_acceptinterview_6
rename q64_1 p_passinterview_6
rename q66_1 p_acceptoffer_6
rename q67 interview_6

* elite black man
rename q95_1 p_acceptinterview_7
rename q94_1 p_passinterview_7
rename q96_1 p_acceptoffer_7
rename q97 interview_7

* nonelite black man
rename q101_1 p_acceptinterview_8
rename q100_1 p_passinterview_8
rename q102_1 p_acceptoffer_8
rename q103 interview_8

* nonelite white man
rename q89_1 p_acceptinterview_9
rename q88_1 p_passinterview_9
rename q90_1 p_acceptoffer_9
rename q91 interview_9

* reshape
keep responseid p_* interview_* gender_* race_* educ_* firm_* exp_hirese 
reshape long p_acceptinterview p_passinterview p_acceptoffer interview , i(responseid) j(type, string)

destring p_*, replace

gen callback = interview=="Yes"
drop interview
rename callback interview



gen c_white = inlist(type,"_2","_3","_6","_9")
gen c_black = inlist(type,"_4","_5","_7","_8")
gen c_female = inlist(type,"_2","_3","_4","_5")
gen c_male = inlist(type,"_6","_7","_8","_9")
gen c_elite = inlist(type,"_2","_4","_6","_7")
gen c_nonelite = inlist(type,"_3","_5","_8","_9")

drop type

order responseid gender_* race_* exp_hirese  educ_* firm_* p_acceptinterview p_passinterview p_acceptoffer interview c_*


foreach x in p_acceptinterview p_passinterview p_acceptoffer { 
	replace `x' = `x'/100
}

save "../Data/Clean/clean_accuracy_candidates.dta", replace
